package logic

import (
	"context"
	"real/realrpc/realrpc"

	"real/api/internal/svc"
	"real/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RealmLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRealmLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RealmLogic {
	return &RealmLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RealmLogic) Realm(req *types.RealmRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	name, err := l.svcCtx.RealRpc.RealName(l.ctx, &realrpc.RealNameRequest{
		Id:       req.Id,
		IdCard:   req.IdCard,
		RealName: req.RealName,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	} else {
		return &types.Response{
			Message: "实名认证成功",
			Code:    200,
			Data:    name,
		}, nil

	}

}
